package com.yaoxuguang.concurrence.threadBase.interrupted;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.threadBase.interrupted
 * @Description: 利用抛异常停止线程
 * @date 2018年12月17日15:24
 */
public class UseExceptionInterrupteThread extends Thread{
    @Override
    public void run() {
       /* for (int i = 0; i < 50000; i++) {
            if(this.interrupted()){
                System.out.println("线程停止了，我要退出");
                break;
            }
            System.out.println("i="+(i+1));
        }
        System.out.println("跳出for循环，我要输出了...");*/
        try {
            for (int i = 0; i < 50000; i++) {
                if(this.interrupted()){
                    System.out.println("线程停止了，我要退出");
                   throw new InterruptedException();
                }
                System.out.println("i="+(i+1));
            }
            System.out.println("跳出for循环，我要输出了...");
        } catch (InterruptedException e) {
            System.out.println("catch方法中...");
            e.printStackTrace();
        }
    }
}
